home *** CD-ROM | disk | FTP | other *** search
/ Power DOS 1996 July / Power DOS - July 1996.iso / sound / c_labs / devinfo / mpu401.exe / SBCUTILS.C < prev    next >
C/C++ Source or Header  |  1996-04-18  |  5KB  |  147 lines

  1. /* -------------------------------------------------------------------------- */
  2. /* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      */
  3. /* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE        */
  4. /* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR      */
  5. /* PURPOSE.                                                                   */
  6. /*                                                                            */
  7. /* You have a royalty-free right to use, modify, reproduce and                */
  8. /* distribute the Sample Files (and/or any modified version) in               */
  9. /* any way you find useful, provided that you agree that                      */
  10. /* Creative has no warranty obligations or liability for any Sample Files.    */
  11. /*----------------------------------------------------------------------------*/
  12.  
  13.  
  14. /* ---------------------------------------------------------------------------
  15.   Program:  Sound Blaster Utilities
  16.   Filename: SBCUTILS.C
  17.   Author:   Scott E. Sindorf
  18.   Language: Borland C
  19.   Date:     30 Jun 93
  20.   
  21.   Copyright (c) 1993 Creative Labs, Inc.
  22. -----------------------------------------------------------------------------*/
  23. #include <conio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include "sbcutils.h"
  28.  
  29. BLASTREC blastInfo;
  30.  
  31. /************************************************************************
  32.  * GETBLASTINFO: Retreives BLASTER environment variable.
  33.  *
  34.  * Input: blastInfo - Structure which receives information.
  35.  *
  36.  * Output: result - ERROR if the variable is not found..
  37.  *                  OK if it is found.
  38.  ************************************************************************/
  39.  
  40. int GetBlastInfo(BLASTREC *blastInfo)
  41.     {
  42.     char *blastStr;
  43.     char *tempStr;
  44.     int result = OK,
  45.         i;
  46.  
  47.     blastInfo->baseAddr = 0;                                // clear record
  48.     blastInfo->DSPint = 0;
  49.     blastInfo->DMA8 = 0;
  50.     blastInfo->model = 0;
  51.     blastInfo->DMA16 = 0;
  52.     blastInfo->midiPort = 0;
  53.  
  54.     blastStr = getenv("BLASTER");
  55.  
  56.     if(blastStr)
  57.         {
  58.         tempStr = strtok(blastStr, " ");
  59.         switch(toupper(tempStr[0]))
  60.             {
  61.             case 'A':
  62.                 blastInfo->baseAddr = strtol(tempStr + 1, NULL, 16);
  63.                 break;
  64.             case 'I':
  65.                 blastInfo->DSPint = (unsigned char) atoi(tempStr + 1);
  66.                 break;
  67.             case 'D':
  68.                 blastInfo->DMA8 = (unsigned char) atoi(tempStr + 1);
  69.                 break;
  70.             case 'T':
  71.                 blastInfo->model = (unsigned char) atoi(tempStr + 1);
  72.                 break;
  73.             case 'H':
  74.                 blastInfo->DMA16 = (unsigned char) atoi(tempStr + 1);
  75.                 break;
  76.             case 'P':
  77.                 blastInfo->midiPort = strtol(tempStr + 1, NULL, 16);
  78.                 break;
  79.             default:
  80.                 break;
  81.             }
  82.  
  83.         for(i = 0; i < 5; i++)
  84.             {
  85.             tempStr = strtok(NULL, " ");
  86.             switch(toupper(tempStr[0]))
  87.                 {
  88.                 case 'A':
  89.                     blastInfo->baseAddr = strtol(tempStr + 1, NULL, 16);
  90.                     break;
  91.                 case 'I':
  92.                     blastInfo->DSPint = (unsigned char) atoi(tempStr + 1);
  93.                     break;
  94.                 case 'D':
  95.                     blastInfo->DMA8 = (unsigned char) atoi(tempStr + 1);
  96.                     break;
  97.                 case 'T':
  98.                     blastInfo->model = (unsigned char) atoi(tempStr + 1);
  99.                     break;
  100.                 case 'H':
  101.                     blastInfo->DMA16 = (unsigned char) atoi(tempStr + 1);
  102.                     break;
  103.                 case 'P':
  104.                     blastInfo->midiPort = strtol(tempStr + 1, NULL, 16);
  105.                     break;
  106.                 default:
  107.                     break;
  108.                 }
  109.             }
  110.         }
  111.     else
  112.         result = ERROR;
  113.  
  114.     return(result);
  115.     }
  116.  
  117. /************************************************************************
  118.  * DSPReset: Resets the DSP on the Sound Blaster card.
  119.  *
  120.  * Input:  none
  121.  *
  122.  * Output: OK (0) or ERROR (-1).
  123.  *
  124.  ************************************************************************/
  125. int DSPReset(void)
  126. {
  127.   int result = ERROR,
  128.       i,
  129.       j;
  130.  
  131.   outp(blastInfo.baseAddr + DSP_RST, 1);
  132.     for(i = 0; i < 100; i++);                                      // delay more than 3us
  133.   outp(blastInfo.baseAddr + DSP_RST, 0);
  134.  
  135.   for(i = 0; (i < 32) && (result != DSP_RST_OK); i++)
  136.   {
  137.     for(j = 0; (j < 512) && (inp(blastInfo.baseAddr + DSP_RD_ST) < MSB);
  138.       j++);
  139.     if(j < 512)
  140.       result = inp(blastInfo.baseAddr + DSP_RD);
  141.   }
  142.   if(result == DSP_RST_OK)
  143.     result = OK;
  144.  
  145.   return(result);
  146. }
  147.